package com.dao.imp;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;

import com.dao.CourseinfoDao;
import com.dao.core.DaoBaseImp;
import com.page.PageDiv;
import com.pojo.Courseinfo;

public class CourseinfoDaoImp extends DaoBaseImp<Courseinfo> implements CourseinfoDao{

	@Override
	public Courseinfo getCourseinfoById(Integer id) {
		if(null==id||id<1){
			return null;
		}
		return (Courseinfo) getSession().get(Courseinfo.class, id);
	}

	@Override
	public List<Courseinfo> getCourseinfoByids(Integer[] ids) {
		if(null==ids||ids.length<1)
			return null;
		List<Courseinfo> list = new ArrayList<Courseinfo>();
		for(int i=0;i<ids.length;i++){
			list.add((Courseinfo)getSession().get(Courseinfo.class, ids[i]));
		}
		
		return list;
	}

	@Override
	public PageDiv<Courseinfo> getAllCourseinfobypage(int offSet, int pageSize) {
		if(offSet>=0&&pageSize>0)
		{
			String hql="from Courseinfo";
			Query q=getSession().createQuery(hql);
			q.setMaxResults(pageSize);
			q.setFirstResult(offSet);
			List<Courseinfo> list=q.list();
			int totalCount=this.getCountQuery(hql);
			return new PageDiv<Courseinfo>(offSet,pageSize,totalCount,list);
		}
			
		else
			return new PageDiv<Courseinfo>();
	}
	
	
	 

}
